//-----------------------------------------------------------------------------
//
//  <No description>
//
//  Microsoft Zenith Project
//  Copyright ?001,2002,2003,2004 Microsoft Corporation
//  One Microsoft Way, Redmond, Washington 98052-6399 U.S.A.
//  All rights reserved.
//  MICROSOFT CONFIDENTIAL
//
//-----------------------------------------------------------------------------

#include <tinyhal.h>
#include "..\..\SD_BL.h"

//--//

void SD_BS_Driver::InitializeInsertIsr(void)
{
	return;
}

BOOL SD_BS_Driver::SDCardIsInserted(void)
{
    return FALSE;
}

void SD_BS_Driver::InsertISR(GPIO_PIN Pin, BOOL PinState, void *Param)
{
	return;
}

//--//

BOOL SD_BS_Driver::ChipInitialize(void *context)
{
	return FALSE;
}

BOOL SD_BS_Driver::ChipUnInitialize(void *context)
{
	return FALSE;
}

const BlockDeviceInfo *SD_BS_Driver::GetDeviceInfo(void *context)
{
	return NULL;
}

BOOL SD_BS_Driver::ReadSector(void *context, SectorAddress StartSector, UINT32 NumSectors, BYTE *pSectorBuff, SectorMetadata *pSectorMetadata)
{
	return FALSE;
}

BOOL SD_BS_Driver::ReadFromPhysicalAddress(void *context, UINT32 PhysicalAddress, UINT32 NumOfBytes, BYTE *pSectorBuff, SectorMetadata *pSectorMetadata)
{
	return FALSE;
}

BOOL SD_BS_Driver::WriteSector(void *context, SectorAddress StartSector, UINT32 NumSectors, BYTE *pSectorBuff, SectorMetadata *pSectorMetadata)
{
	return FALSE;
}

BOOL SD_BS_Driver::WriteToPhysicalAddress(void *context, UINT32 PhysicalAddress, UINT32 NumOfBytes, BYTE *pSectorBuff, SectorMetadata *pSectorMetadata)
{
	return FALSE;
}

BOOL SD_BS_Driver::IsBlockErased(void *context, SectorAddress Sector)
{
	return FALSE;
}

BOOL SD_BS_Driver::EraseBlock(void *context, SectorAddress Sector)
{
	return FALSE;
}

BOOL SD_BS_Driver::GetBlockStatus(void *context, SectorAddress Address, BlockStatus &Status)
{
	return FALSE;
}

BOOL SD_BS_Driver::SetBlockStatus(void *context, SectorAddress Address, BlockStatus Status)
{
	return FALSE;
}

void SD_BS_Driver::SetPowerState(void *context, BOOL State)
{
	return;
}

BOOL SD_BS_Driver::PhysicalAddressToSectorAddress(void *context, UINT32 PhyAddress, UINT32 LengthInBytes, SectorAddress &SectAddress)
{
	return FALSE;
}

BOOL SD_BS_Driver::SectorAddressToPhysicalAddress(void *context, SectorAddress SectAddress, UINT32 NumSectors, UINT32 &PhyAddress)
{
	return FALSE;
}

BOOL SD_BS_Driver::FindForBlockUsage(void *context, UINT32 BlockUsage, UINT32 StatusMask, SectorAddress &Address, const BlockRegionInfo **pBlockRegionInfo)
{
	return FALSE;
}

BOOL FindBlock(void *context, SectorAddress Address, UINT32 &BlkIndex, UINT32 &RegionIndex, UINT32 &AbsBlkIndex, const BlockRegionInfo **pBlockRegionInfo)
{
	return FALSE;
}

UINT32 SD_BS_Driver::MaxSectorWrite_uSec(void *context)
{
	return 0;
}

UINT32 SD_BS_Driver::MaxBlockErase_uSec(void *context)
{
	return 0;
}

//--//

#if DEBUG_SD == 2

static inline void nul(const char *fmt, ...) {}

static void msac_dbg_dump(char *msg, void *buffer, unsigned len, unsigned size)
{
    unsigned i, max;
    UINT32 *nf32 = (UINT32*) buffer;
    UINT16 *nf16 = (UINT16*) buffer;
    UINT8 *nf8  = (UINT8*) buffer;

    SD_PRINT("%s: ",msg);

    if (len > 8)
        max = 8;
    else
        max = len;

    for (i=0;i<max;i++) {
        if (size == 4)
            SD_PRINT("%8.8x ",*nf32++);
        else if (size == 2)
            SD_PRINT("%4.4x ",*nf16++&0xffff);
        else {
            SD_PRINT("%2.2x ",*nf8++&0xff);
        }
    }

    if (max < len)
        SD_PRINT("...");

    SD_PRINT("\r\n");
}

static int dumpline(BYTE *data, UINT32 addr, size_t data_len, char *buffer, size_t len_buffer)
{
    int  k;
    BYTE *rd;

    hal_snprintf(buffer, len_buffer, " %8.8X:", addr );
    for (k=0,rd = data;k<16;k++)
    {
        if (k<data_len)
        {
            hal_snprintf(&buffer[10+(k*3)], (len_buffer - (10+(k*3))), " %2.2X", *rd++);
        }
        else
        {
            hal_snprintf(&buffer[10+(k*3)], (len_buffer - (10+(k*3))), " ..");
        }
    }
    strcat (buffer, " ");
    for (k=0,rd = data; k<16; k++) 
    {
        if (k<data_len&&(*rd>=0x20 && *rd<=0x7e))
        {
            hal_snprintf(&buffer[10+(16*3)+1+k], (len_buffer - (10+(16*3)+1+k)), " %c", *rd++);
        }
        else
        {
            hal_snprintf(&buffer[10+(16*3)+1+k], (len_buffer - (10+(16*3)+1+k)), ".");
        }
    }
    strcat (buffer, "\r\n");
    return (addr += 16);
}

static void msac_dump(BYTE *buf, size_t len)
{
    char line[256];
    UINT32 act_adr;
    
    act_adr = 0;
    do {
        act_adr = dumpline((buf+act_adr), act_adr, (len-act_adr), line, 256);
        SD_PRINT(line);
    } while ((act_adr) < len);
}

#endif

